/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.desarrollosw2.dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mx.its.desarrollosw2.Libro;

/**
 *
 * @author sistemas
 */
@Stateless
public class LibroDao extends AbstractDao<Libro> implements LibroDaoLocal {
    @PersistenceContext(unitName = "Biblioteca8EE-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public LibroDao() {
        super(Libro.class);
    }
    
    @Override
    public boolean  findDuplicity(Libro book){
       Query q=em.createNamedQuery("Libro.findByIsbn"); 
       q.setParameter("isbn", book.getIsbn());
     return !q.getResultList().isEmpty();
    }

    @Override
    public Libro findBookForLend(String claveLibro){
    Query q=em.createNamedQuery("Libro.findByClave");
q.setParameter("Clave",claveLibro);
if(!q.getResultList().isEmpty()){
    return (Libro)q.getResultList().get(0);
}else{
    return null;
}
}
}
